from utils.convert import header_placeholder, add_ad_service, footer_placeholder
from bs4 import BeautifulSoup

img_list = [
    {
        "photo": "https://bio-mercury-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/yuanye_main.png"
    },
    {
        "photo": "https://bio-mercury-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/photos%5C2.jpg"
    },
    {
        "photo": "https://bio-mercury-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/photos%5C3.jpg"
    },
    {
        "photo": "https://bio-mercury-1316961827.cos.ap-guangzhou.myqcloud.com/photos/%E6%BA%90%E5%8F%B6/photos%5C4.jpg"
    },
    {
        "photo": "https://images.rjmart.cn/image/enqu62up/860d4319-09b2-4af2-8cde-3bb94773fdee.jpg"
    },
]


def process_des(html):
    # 清除空 img 标签
    img_str = '<img src=""/>\n'
    content = "<div>" + html.replace(img_str, "") + "</div>"
    soup = BeautifulSoup(content, "html.parser")

    # 删除data:image 的img 标签
    img_tag = soup.find("img", src=lambda x: x and x.startswith("data:image"))
    if img_tag:
        img_tag.decompose()

    # 删除旧版广告
    old_ad_tag = soup.find("div", attrs={"id": "con_header"})
    if old_ad_tag:
        old_ad_tag.decompose()
    # 创建新 html
    _description = BeautifulSoup("", "html.parser")
    div_dom = _description.new_tag("div", attrs={"class": "cxsw_description"})

    # 创建样式标签
    # style_tag = soup.new_tag("style")
    # style_tag.string = protein_style
    # div_dom.append(style_tag)
    div_dom.append(soup)

    return add_ad_service() + header_placeholder() + str(div_dom) + footer_placeholder()
